import { defHttp } from '@/utils/http/axios';
import { LoginParams, LoginResultModel, GetUserInfoModel } from './model/userModel';
import { useUserStore } from '@/store/modules/user';
import { ErrorMessageMode } from '#/axios';
import { getAppEnvConfig } from '@/utils/env';
const { VITE_GLOB_AUTH_PRE_FIX } =getAppEnvConfig();
const Api = {
  Login : `${VITE_GLOB_AUTH_PRE_FIX}/login`,
  Logout : `${VITE_GLOB_AUTH_PRE_FIX}/logout`,
  GetUserInfo : `${VITE_GLOB_AUTH_PRE_FIX}/login`,
  GetPermCode : `${VITE_GLOB_AUTH_PRE_FIX}/login`,
  TestRetry : `${VITE_GLOB_AUTH_PRE_FIX}/login`,
}
// enum Api {
  //   Login = '/login',
  //   Logout = '/logout',
  //   GetUserInfo = '/getUserInfo',
  //   GetPermCode = '/getPermCode',
  //   TestRetry = '/testRetry',
  // }
  
  /**
   * @description: user login api
  */
 export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
   return defHttp.post<LoginResultModel>(
     {
       url: Api.Login,
       params,
      },
      {
        errorMessageMode: mode,
      },
    );
  }
  
  /**
   * @description: getUserInfo
  */
 export function getUserInfo() {
  const userStore = useUserStore();
  return userStore.getUserInfo
  // return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}

export function doLogout() {
  return defHttp.post({ url: Api.Logout });
}

export function testRetry() {
  return defHttp.get(
    { url: Api.TestRetry },
    {
      retryRequest: {
        isOpenRetry: true,
        count: 5,
        waitTime: 1000,
      },
    },
  );
}
